<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript">
	$(function() {
		// CKEditor
		CKEDITOR.replace( 'ckeditor', {
			height: 200
		});
		CKEDITOR.on('instanceReady', function (e){
			modal.centerModal();
		})
		
		$("#msg-form").find("select[name='msg.type']").change(function() {
			var type = $(this).val();
			if(type==1) 
				$("#user-p").hide();
			else if(type==2) 
				$("#user-p").show();
			modal.centerModal();
		})
		
		var msgId = "${msg.id}";
		if(msgId!=null&&msgId!='') {
			var type = "${msg.type}";
			$("#msg-form").find("select[name='msg.type']").val(type);
			if(type==1)
				$("#user-p").hide();
			else if(type==2)
				$("#user-p").show();
			modal.centerModal();
			var ids = "${userIds}";
			$.each($("input[name='userIds']"),function(i, n){
				var value = $(n).val();
				var index = ids.indexOf(value);
				if(index!=-1) $(n).attr("checked", "checked");
			})
		}
	})
</script>
<form id="msg-form">
	<input type="hidden" name="msg.id" value="${msg.id }">
	<c:choose>
		<c:when test="${param.isProMsg ne null }">
			<input type="hidden" name="msg.is_promsg" value="${param.isProMsg }">
		</c:when>
		<c:otherwise>
			<input type="hidden" name="msg.is_promsg" value="${msg.is_promsg }">
		</c:otherwise>
	</c:choose>
	
	<h3 class="thin underline">消息信息</h3>
	<p class="inline-label button-height">
		<label class="label">标题：</label>
		<input type="text" name="msg.title" class="input" value="${msg.title }">
	</p>
	<p class="inline-label button-height">
		<label class="label">分类：</label>
		<select name="msg.type" class="select">
			<option value="">--请选择--</option>
			<c:if test="${param.isProMsg eq 0 }">
				<option value="1">系统公告</option>
			</c:if>
			<option value="2">普通消息</option>
		</select>
	</p>
	<div class="inline-label button-height" id="user-p" style="display:none;">
		<label class="label">用户：</label>
		<fieldset class="fieldset">
			<legend class="legend">教师</legend>
			<c:forEach items="${teachers }" var="teacher">
				<input type="checkbox" name="userIds" value="${teacher.id }"> 
				<label for="radio-1" class="label">${teacher.username }</label>
			</c:forEach>
		</fieldset>
		<fieldset class="fieldset">
			<legend class="legend">学生</legend>
			<c:forEach items="${students }" var="student">
				<input type="checkbox" name="userIds" value="${student.id }"> 
				<label for="radio-1" class="label">${student.username }</label>
			</c:forEach>
		</fieldset>
		<fieldset class="fieldset">
			<legend class="legend">专家</legend>
			<c:forEach items="${experts }" var="expert">
				<input type="checkbox" name="userIds" value="${expert.id }"> 
				<label for="radio-1" class="label">${expert.username }</label>
			</c:forEach>
		</fieldset>
	</div>
	<p/>
	<p class="inline-label button-height">
		<label class="label">内容：</label>
		<textarea id="ckeditor">${msg.content }</textarea>
	</p>
</form>
    